package com.ruoyi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.CategoryThree;
import com.ruoyi.service.ICategoryThreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 三级分类
 */
@RestController
@RequestMapping("/webshop/categoryThree")
public class CategoryThreeController extends BaseController {
    @Autowired
    private ICategoryThreeService categoryThreeService;

    // 全查
    @GetMapping("/list")
    public List<CategoryThree> list() {
        List<CategoryThree> list = categoryThreeService.list();
        return list;
    }

    @GetMapping("/listForPage")
    public TableDataInfo listForPage(CategoryThree categoryThree) {
        System.out.println("categoryThree = " + categoryThree);
        startPage();
        List<CategoryThree> list = categoryThreeService.listForPage(categoryThree);

        return getDataTable(list);
    }

    // 根据id查一条
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        System.out.println("id = " + id);
        CategoryThree categoryThree = categoryThreeService.getById(id);
        return success(categoryThree);
    }

    // 添加
    @PostMapping()
    public AjaxResult add(@RequestBody CategoryThree categoryThree) {
        System.out.println("categoryThree = " + categoryThree);
        int add = categoryThreeService.save(categoryThree);
        return toAjax(add);
    }

    // 修改
    @PutMapping()
    public AjaxResult edit(@RequestBody CategoryThree categoryThree) {
        System.out.println("categoryThree = " + categoryThree);
        int edit = categoryThreeService.updateById(categoryThree);
        return toAjax(edit);
    }

    // 根据ids删除多条
    @DeleteMapping("/{ids}")
    public AjaxResult deleteMany(@PathVariable Long[] ids) {
        System.out.println("ids = " + ids);
        int delete = categoryThreeService.removeByIds(ids);
        return toAjax(delete);
    }
}
